<?php

namespace App\Hospital\Controllers;

use App\Hospital\Repositories\HospitalTeam;
use App\Models\HospitalTeam as ModelsHospitalTeam;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Dropdown;
use Dcat\Admin\Layout\Content;

class HospitalTeamController extends AdminController
{


    protected function description()
    {
        $this->description['index'] = '家医团队添加后系统会自动根据团队类型分配签约用户';
        $this->description['create'] = '家医团队添加后系统会自动根据团队类型分配签约用户';

        return $this->description;
    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new HospitalTeam(), function (Grid $grid) {
            $grid->model()->where('hospital_id',Admin::user()->hospital_id);
            $grid->column('name');
            $grid->column('intro');
            $grid->column('iamge')->image(config('asset_iamge_url'), 100, 100);
            $grid->column('slogan');
            $grid->column('type')->using(ModelsHospitalTeam::$typeTxt);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->disableFilterButton();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new HospitalTeam(), function (Show $show) {
            $show->field('name');
            $show->field('intro');
            $show->field('iamge')->image();;
            $show->field('slogan');
            $show->field('type')->using(ModelsHospitalTeam::$typeTxt);
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new HospitalTeam(), function (Form $form) {
            $form->hidden('hospital_id')->value(Admin::user()->hospital_id);
            $form->text('name')->required();
            $form->text('director','负责人姓名')->required();

            $form->image('iamge')
                ->autoUpload() //选择图片后自动上传
                ->uniqueName()
                ->accept('jpg,png,gif,jpeg', 'image/*')
                ->maxSize(512)
                ->disk('oss')->required();
            $form->textarea('intro')->required();
            $form->text('slogan')->required();
            $form->select('type')->options(ModelsHospitalTeam::$typeTxt)->required();

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
